package cn.net.shuxing.yifu.common.bean;

import java.lang.reflect.Method;
import java.time.LocalDate;
import java.time.LocalDateTime;

public abstract class DateBean extends BaseBean {


    @Override
    public void resetCreateTimeAndUpdateTime()
    {
        resetCreateDateAndUpdateTime();
    }

    public void resetCreateDateAndUpdateTime()
    {
        try{
            Class<? extends BaseBean> beanClass = this.getClass();
            Method setCreateDate = beanClass.getMethod("setCreateDate", LocalDate.class);
            Method setUpdateTime = beanClass.getMethod("setUpdateTime", LocalDateTime.class);

            LocalDate localDate = LocalDate.now();
            LocalDateTime localDateTime = LocalDateTime.now();
            setCreateDate.invoke(this,localDate);
            setUpdateTime.invoke(this,localDateTime);

        }catch(Exception e){

        }
    }

    public abstract void setCreateDate(LocalDate localDate);

    public abstract LocalDate getCreateDate();

    @Override
    public void clearCreateTimeAndUpdateTime()
    {
        clearCreateDateAndUpdateTime();
    }

    public void clearCreateDateAndUpdateTime()
    {
        try{
            Class<? extends BaseBean> beanClass = this.getClass();
            Method setCreateDate = beanClass.getMethod("setCreateDate", LocalDate.class);
            Method setUpdateTime = beanClass.getMethod("setUpdateTime", LocalDateTime.class);

            LocalDate localDate = null;
            LocalDateTime localDateTime = null;
            setCreateDate.invoke(this, localDate);
            setUpdateTime.invoke(this,localDateTime);

        }catch(Exception e){

        }
    }
}
